<?php

namespace app\admin\controller;

use app\common\controller\AliOss;
use think\Validate;

/**
 * 文件控制器
 * 主要用于下载模型的文件上传和下载
 */
class File extends Home
{

    /* 文件上传 */
    public function upload()
    {
        if (request()->isPost()) {
            $file = isset($_FILES["fileUp"]) ? $_FILES['fileUp'] : $_FILES['file'];
            $res = AliOss::uploadFile('hongming/pictures', $file, 2);
            return $res;
        }
    }

//    /* 下载文件 */
//    public function download($id = null){
//        if(empty($id) || !is_numeric($id)){
//            $this->error('参数错误！');
//        }
//
//        $logic = D('Download', 'Logic');
//        if(!$logic->download($id)){
//            $this->error($logic->getError());
//        }
//
//    }

    /**
     * 上传图片
     * @author huajie <banhuajie@163.com>
     */
    public function uploadPicture()
    {
        if (request()->isPost()) {
            $file = isset($_FILES['download']) ? $_FILES['download'] : $_FILES['file'];
            $res = AliOss::uploadFile('hongming/pictures', $file);
            return json_encode($res);
        }
    }

    /**
     * 上传视频
     * @return string
     */
    public function uploadVideo()
    {
        if (request()->isPost()) {
            $file = isset($_FILES['download']) ? $_FILES['download'] : $_FILES['file'];
            $res = AliOss::uploadFile('hongming/videos', $file);
            return json_encode($res);
        }
    }
}
